home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PPCxDMS / source.lha / src / u_medium.c < prev    next >
C/C++ Source or Header  |  1998-02-28  |  1KB  |  67 lines

  1.  
  2. /*
  3.  *     xDMS  v1.1  -  Portable DMS archive unpacker  -  Public Domain
  4.  *     Written by     Andre R. de la Rocha  <adlroc@usa.net>
  5.  *
  6.  *     Main decompression functions used in MEDIUM mode
  7.  *
  8.  */
  9.  
  10.  
  11. #include <string.h>
  12.  
  13. #include "cdata.h"
  14. #include "u_medium.h"
  15. #include "getbits.h"
  16. #include "tables.h"
  17.  
  18.  
  19. #define MBITMASK 0x3fff
  20.  
  21.  
  22. static USHORT medium_text_loc;
  23.  
  24.  
  25.  
  26. void Init_MEDIUM(void){
  27.     medium_text_loc = 0x3fbe;
  28.     memset(text,0,0x3fc0);
  29. }
  30.  
  31.  
  32.  
  33. USHORT Unpack_MEDIUM(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){
  34.     USHORT i, j, c;
  35.     UCHAR u, *outend;
  36.  
  37.  
  38.     initbitbuf(in);
  39.  
  40.     outend = out+origsize;
  41.     while (out < outend) {
  42.         if (GETBITS(1)!=0) {
  43.             DROPBITS(1);
  44.             *out++ = text[medium_text_loc++ & MBITMASK] = (UCHAR)GETBITS(8);
  45.             DROPBITS(8);
  46.         } else {
  47.             DROPBITS(1);
  48.             c = GETBITS(8);  DROPBITS(8);
  49.             j = (USHORT) (d_code[c]+3);
  50.             u = d_len[c];
  51.             c = (USHORT) (((c << u) | GETBITS(u)) & 0xff);  DROPBITS(u);
  52.             u = d_len[c];
  53.             c = (USHORT) ((d_code[c] << 8) | (((c << u) | GETBITS(u)) & 0xff));  DROPBITS(u);
  54.             i = (USHORT) (medium_text_loc - c - 1);
  55.  
  56.             while(j--) *out++ = text[medium_text_loc++ & MBITMASK] = text[i++ & MBITMASK];
  57.             
  58.         }
  59.     }
  60.     medium_text_loc = (USHORT)((medium_text_loc+66) & MBITMASK);
  61.     if (!(flags & 1)) Init_MEDIUM();
  62.  
  63.     return 0;
  64. }
  65.  
  66.  
  67.